<template>
  <section :class="!isSetPageBackground ? 'c-bg-white' : ''">
    <cust-title-com v-if="item.isShowTitle"
      :marginSettings="marginSettings"
      :headLine="headLine"
      :titleName="item.title || '社群'"
      :showMoreType="item.showMoreType"
      :titleDesc="item.desc"
      :showMore="item.isShowMore"
      :launchWeapp="launchWeapp"
      @clickMore="clickMore"
    ></cust-title-com>
    <social-group-item :borderRadius="borderRadius" :marginSettings="marginSettings" :headLine="headLine" :visible="item.visible" :coverStyleType="item.items.coverStyleType" :itemList="item.items.prods" :isFromM7="true" :itemType="item.items.orderBy" :pageName="pageName" :showCount="item.items.count" :showMore="item.isShowMoreBottom" @clickMore="clickMore"></social-group-item>
  </section>
</template>
<script>
import custTitleCom from "@/components/templates/custIndexTemp/custTitleCom.vue";
import socialGroupItem from "@/components/templates/socialGroupItem.vue";
import { appRouterChange } from "@/mixin/appRouterPush.js";
import { utilJs } from "@/utils/common.js";
import { custIndex } from "@/mixin/custIndex.js";
export default {
  mixins: [appRouterChange, custIndex],
  components: {
    custTitleCom,
    socialGroupItem,
  },
  props: {
    item: {
      type: Object,
      default: () => {
        return {}
      },
    },
    pageName: {//首页INDEX 预览页PREVIEW_INDEX 微页面MICRO_PAGE
      type: String,
      default: "INDEX"
    },
  },
  data() {
    return {
      isSetPageBackground: sessionStorage.getItem("isSetPageBackground") || 0,
      launchWeapp: null, // 存储组件标题查看更多跳转到小程序得数据
    };
  },
  computed: {
    borderRadius() {
      return this.item.styleParam && this.item.styleParam.borderRadius ? this.item.styleParam.borderRadius : null
    },
    headLine() {
      return this.item.styleParam && this.item.styleParam.headLine ? this.item.styleParam.headLine : null
    },
    marginSettings() {
      return this.item.styleParam && this.item.styleParam.marginSettings ? this.item.styleParam.marginSettings : null
    },
  },
  methods: {
    clickMore() {
      if (this.pageName == 'PREVIEW_INDEX') {
        return;
      }
      let toPath = "";
      if (this.item.redirect && this.item.redirect.type == 3) {
        toPath = this.cateUrl(this.item.redirect.group[0].level1CatId, this.item.redirect.group[0].level2CatId, this.item.redirect.group[0].level3CatId, this.item.redirect.group[0].groupName);
        this.iosAppRouteChange(toPath);
      } else if (this.item.redirect && this.item.redirect.type == 4) {
        if (this.item.moreInfo.navId == "linkToMiniProgram") {
          utilJs.checkWxApp(); // 再次调用是为了跳转小程序返回后避免小程序环境值判断错误
          this.$nextTick(() => {
            // 微信需要判断是否是小程序环境 h5跳转采用组件跳转 小程序跳转使用跳转到小程序中间页面再点击跳转到其他小程序
            if (localStorage.getItem('isWxApp')) {
              let query = this.item.moreInfo.appID ? `?appId=${this.item.moreInfo.appID}&path=${encodeURIComponent(JSON.stringify(this.item.moreInfo.wechatUrl))}` : `?shortLink=${encodeURIComponent(this.item.moreInfo.wechatUrl)}`;
              utilJs.miniProgramGoTo('push', '/pages/home/goWxApp/index' + query);
            } else {
              if (!this.item.moreInfo || (this.item.moreInfo && !this.item.moreInfo.appID)) return
              this.launchWeapp = {
                appID: this.item.moreInfo.appID,
                wechatUrl: this.item.moreInfo.wechatUrl,
              }
            }
          })
        }
        this.commonModuleRouterPush(this.item.moreInfo)
      } else {
        toPath = "/homePage/socialGroup/socialGroupList";
        this.iosAppRouteChange(toPath);
      }
    },
  },
};
</script>

<style scoped>
</style>
